package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.ResponseResult;
import com.heima.model.wemeida.dtos.WmMaterialDto;
import com.heima.model.wemeida.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 上传素材
     */
    @PostMapping("/upload_picture")
    public ResponseResult<WmMaterial> uploadPicture(MultipartFile multipartFile){
        return wmMaterialService.uploadPicture(multipartFile);
    }

    /**
     * 素材查询
     */
    @PostMapping("/list")
    public ResponseResult<List<WmMaterial>> list(@RequestBody WmMaterialDto dto){
        return wmMaterialService.findList(dto);
    }

    /**
     * 收藏
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id){
        return wmMaterialService.updateCollect(id,1);
    }

    /**
     * 取消收藏
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id){
        return wmMaterialService.updateCollect(id,0);
    }

    /**
     * 删除素材
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable("id") Integer id){
        return wmMaterialService.delPicture(id);
    }
}
